import { createWebHistory, createRouter, createWebHashHistory } from 'vue-router'
import Layout from '@/layout'


// 创建路由
export const constantRoutes = [
    {
        path : '',
        component : Layout,
        redirect : '/index',  
        children:[
            {
                path: '/index',
                component : () => import('@/views/index'),
                name : 'Index',
                meta : { title: '首页' , icon : 'dashboard'},
            }  
        ]
    },{
        path : '/user',
        component : () => import('@/views/system/user/profile/index'),
        name : 'user',
        meta : { title: '个人中心' , icon : 'user'}
    }

]

// 创建路由器
const router = createRouter({
    history : createWebHashHistory(),
    routes : constantRoutes,
    // 切换页面后置顶
    scrollBehavior(to, from, savedPosition){
        if(savedPosition){
            return savedPosition
        }else {
            return { top : 0 }
        }
    }
})


// 默认暴露路由器
export default router